var PurOrgHeadList = function() {
	var left_margin_step = 15;
	$("#qryPurOrg").bind(
			'click',
			function() {
				var myts = new Date();
				var formStr = $(this).parents("form").find("#org_filter").serialize();
				jQuery.ajax( {
					type : "POST",
					async : false,
					url : ebvp_context + "/other/filterPurOrg?myts=" + myts,
					dataType : "text",
					data : "&" + formStr,
					success : function(result) {
						if(result != "[]"){
							var orgArr = null;
							if(result != "" && result != null){
								orgArr =eval(result);
								$("#purOrgHeadPicker").find(".tree_list12").empty();
								for ( var loop = 0; loop < orgArr.length; loop++) {
									var obj = orgArr[loop];
//									var a = $("<a></a>").attr("href", "#").addClass(
//											"category_trigger12").attr("margin", 0);
//								    if(obj.orgtype7==true){
//								    	var inputObj = $("<input/>").val(obj.pk_org).attr(
//											"type", "radio").attr("name", "pk_purOrg_intree");
//								    }else{
//								    	var inputObj = $("<input/>").val(obj.pk_org).attr(
//											"type", "radio").attr("disabled","disabled").attr("name", "pk_purOrg_intree");
//								    }
								    var inputObj = $("<input/>").val(obj.pk_org).attr(
											"type", "radio").attr("name", "pk_purOrg_intree");																		
									var label = $("<label></label>").text(obj.name);
									var inputObj1 = $("<input/>").val(obj.pk_org).attr(
											"type", "hidden");
									var inputObj2 = $("<input/>").val(obj.pk_group).attr(
											"type", "hidden");
									var div = $("<div></div>")
											.addClass("tree_category12")
//											.append(a)
											.append(inputObj).append(label).append(inputObj1).append(inputObj2);												
									$("#purOrgHeadPicker").find(".tree_list12")
											.append(div);
								}
						  }
					   }
					}				
				});
				var position = $(this).offset();
				position.top += 25;
				$("#purOrgHeadPicker").slideDown("normal");
				$("#purOrgHeadPicker").offset(position);	
			});

	$("#filterPurOrg").bind(
			'click',
			function() {
				var myts = new Date();
				var formStr = $(this).parents("form").find("#org_filter").serialize();
				jQuery.ajax( {
					type : "POST",
					async : false,
					url : ebvp_context + "/other/filterPurOrg?myts=" + myts,
					dataType : "text",
					data : "&" + formStr,
					success : function(result) {
						if(result != "[]"){
							var orgArr = null;
							if(result != "" && result != null){
								orgArr =eval(result);
								$("#purOrgHeadPicker").find(".tree_list12").empty();
								for ( var loop = 0; loop < orgArr.length; loop++) {
									var obj = orgArr[loop];
//									var a = $("<a></a>").attr("href", "#").addClass(
//											"category_trigger12").attr("margin", 0);
//									if(obj.orgtype7==true){
//								    	var inputObj = $("<input/>").val(obj.pk_org).attr(
//											"type", "radio").attr("name", "pk_purOrg_intree");
//								    }else{
//								    	var inputObj = $("<input/>").val(obj.pk_org).attr(
//											"type", "radio").attr("disabled","disabled").attr("name", "pk_purOrg_intree");
//								    }
								    var inputObj = $("<input/>").val(obj.pk_org).attr(
											"type", "radio").attr("name", "pk_purOrg_intree");									
//									var inputObj = $("<input/>").val(obj.pk_org).attr(
//											"type", "radio").attr("name", "pk_purOrg_intree");	
									var label = $("<label></label>").text(obj.name);
									var inputObj1 = $("<input/>").val(obj.pk_org).attr(
											"type", "hidden");
									var inputObj2 = $("<input/>").val(obj.pk_group).attr(
											"type", "hidden");
									var div = $("<div></div>")
											.addClass("tree_category12")
//											.append(a)
											.append(inputObj).append(label).append(inputObj1).append(inputObj2);												
									$("#purOrgHeadPicker").find(".tree_list12")
											.append(div);
								}
						  }
					   }else{
					   	   $("#purOrgHeadPicker").find(".tree_list12").empty();
					   }
					}				
				});
			});
	
	$(".tree_btns12 .idBtnPicked").live('click', function() {
		var items = $("#purOrgHeadPicker").find("[name='pk_purOrg_intree']");
		if(items != null){
			var str="";
			var pks="";
			var pk_groups="";
			for(var loop=0; loop<items.length; loop++){
				if(items[loop].checked == true){					
					str += $(items[loop]).next("label").html();
					pks += $(items[loop]).next("label").next("input").val();	
					pk_groups+=$(items[loop]).next("label").next("input").next("input").val() ;
					break;
				}
			}
//			var length1=str.length;
//			var length2=pks.length;
//			var length3=pk_groups.length;
			if(str != ""){
				$("#qryPurOrg").val(str).attr("style", "color:black");			
			}
			$("#pk_purOrg").val(pks);
			$("#pk_group").val(pk_groups);
		}
		
		$("#purOrgHeadPicker").slideUp();
		return 0;
		
	});
	
	$(".tree_btns12 .idBtnCancel").live('click', function(){
		$("#org_filter").val("");
		$("#purOrgHeadPicker").slideUp();
	});
	
	this.init = function() {

	};
};

$(function() {
	var purOrgHead = new PurOrgHeadList();
	purOrgHead.init();
});
